package com.wuwei.baseproject.base;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import butterknife.ButterKnife;

import com.union.utils.*;
import com.wuwei.baseproject.UnionApplication;
import com.wuwei.baseproject.activity.LoginCommonActivity;


public abstract class BaseCommonActivity extends AppCompatActivity {
    protected abstract void findWidgets();

    protected Context mContext;

    protected void onCreateView(int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
        mContext = this;
        findWidgets();
        initComponent();
        initListener();
        initHandler();
        asyncRetrive();
        pushAtyToStack();
    }


    public   void initComponent(){

    };

    /**
     * 后退按钮响应事件
     */
    public void onBackClick(View v) {
        finish();
    }

    public void onRightClick(View v){

    }
    protected boolean checkLogin() {
        if (SessionUtils.getUserId().isEmpty()){
            ToastUtils.custom("请先登录");
            IntentUtils.startAty(this,LoginCommonActivity.class);
            return true;
        }
        return false;
    }


    @SuppressWarnings("unchecked")
    protected <T> T findView(int id) {
        return (T) findViewById(id);
    }

    /**
     * 初始化Listener，子类根据需要自行重写
     */
    protected void initListener() {
        return;
    }

    /**
     * 初始化Handler，子类根据需要自行重写
     */
    protected void initHandler() {
        return;
    }



    /**
     * 异步查询网络数据，子类根据需要自行重写
     */
    protected void asyncRetrive() {
        return;
    }

    /**
     * 重试查询网络数据，子类根据需要自行重写
     */
    protected void retryRetrive() {
//        ReflectUtils.invokeMethod(this, "asyncRetrive");
    }



    /**
     * 显示失败信息，默认显示吐司，子类有需要显示界面可自行重写
     */
    protected void showErrorMessage(Integer errorCode, String errorMessage) {
        ToastUtils.custom(errorMessage);
    }

    /**
     * 把当前Activity Push栈中
     */
    private void pushAtyToStack() {
        UnionApplication.push(this);
    }

    /**
     * 把当前Activity Pop出栈
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        UnionApplication.pop(this);
    }

    public void setFullScreen(boolean isFullScreen) {
        if (isFullScreen) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        } else {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        }
    }

    /**
     * 判断是否有网络
     *
     * @return
     */
    protected boolean isNetworkConnected() {
        return NetUtil.isHasNet(this);
    }

    protected void showProgress(String message,
                                boolean isCanceledOnTouchOutside, boolean isCancelable) {
    }

    protected void dismissProgressDialog() {
    }

    @Override
    protected void onResume() {
        super.onResume();
//        JPushInterface.onResume(BaseCommonActivity.this);
//        MobclickAgent.onResume(mContext);
    }

    @Override
    protected void onPause() {
        super.onPause();
//        JPushInterface.onPause(BaseCommonActivity.this);
//        MobclickAgent.onPause(mContext);

    }



}